-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[webview_flutter_wkwebview] Remove specialization of 'map' to fix Swift warning #9810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly removes an explicit type specialization in a Swift map call to resolve a compiler warning. I've added a couple of suggestions. One is to correct the CHANGELOG entry, as the change affects the plugin's source code, not the example app. The other, more critical suggestion is to replace try! with try on the modified line to prevent a potential runtime crash and properly propagate errors, aligning with the function's throwing signature.
| let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar | ||
|
|
||
| let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> { | ||
| let keyValueTuples = try! properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using try! can cause a crash if the map operation throws an error. The closure can throw an error, for example, for an unknown enum case or when sameSitePolicy is used on an older OS version. Since the pigeonDefaultConstructor function is marked with throws, the error should be propagated with try instead of try! to prevent a potential crash.
| let keyValueTuples = try! properties.map { | |
| let keyValueTuples = try properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a Swift expert, @hellohuanlin what's the idiomatic thing to do here? And is that correct in the context of this plugin?
There are no warnings without the !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the caller:
Lines 1654 to 1660 in 27a2302
| do { | |
| api.pigeonRegistrar.instanceManager.addDartCreatedInstance( | |
| try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api, url: urlArg), | |
| withIdentifier: pigeonIdentifierArg) | |
| reply(wrapResult(nil)) | |
| } catch { | |
| reply(wrapError(error)) |
It wraps pigeonDefaultConstructor call under a do/catch block, and if it throws, it replies error to the dart side.
So if you use try here, when it throws, it will be eventually propagated to dart side;
If you use try! here, when it throws, it will crash.
Given that this code is setup this way (throwable method + do/try/catch block), I'd say the expected usage is not to crash. So let's go with try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md
Outdated
Show resolved
Hide resolved
| let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar | ||
|
|
||
| let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> { | ||
| let keyValueTuples = try! properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was complaining because line 13 above in the function declaration already contains the type information [HttpCookiePropertyKey: Any]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! The old rule is that yon can always explicitly provide types, and what's more, sometimes you must explicitly provide types for super long statements where swift compiler fails auto-infer the types).
1c9f84a to
ca25084
Compare
| let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar | ||
|
|
||
| let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> { | ||
| let keyValueTuples = try properties.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't i review this PR before? gosh my memory is getting messed up!
… app to prevent a Swift warning
ca25084 to
b7e28cd
Compare
|
autosubmit label was removed for flutter/packages/9810, because - The status or check suite Mac_arm64 ios_platform_tests_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/packages/9810, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
…to fix Swift warning (flutter/packages#9810)
…to fix Swift warning (flutter/packages#9810)
…to fix Swift warning (flutter/packages#9810)
…to fix Swift warning (flutter/packages#9810)
…to fix Swift warning (flutter/packages#9810)
flutter/packages@1a7075b...3d926aa 2025-11-04 49699333+dependabot[bot]@users.noreply.github.com [dependabot]: Bump com.squareup.okhttp3:okhttp from 5.1.0 to 5.3.0 in /packages/espresso/android (flutter/packages#10348) 2025-11-04 engine-flutter-autoroll@skia.org Roll Flutter from 6f8abdd to 027f2e4 (26 revisions) (flutter/packages#10335) 2025-11-03 stuartmorgan@google.com [google_sign_in] Remove use of OCMock (flutter/packages#10290) 2025-11-03 stuartmorgan@google.com [interactive_media_ads] Pin iOS dependency maximum (flutter/packages#10349) 2025-10-30 magder@google.com [webview_flutter_wkwebview] Remove specialization of 'map' to fix Swift warning (flutter/packages#9810) 2025-10-30 engine-flutter-autoroll@skia.org Roll Flutter from df72035 to 6f8abdd (16 revisions) (flutter/packages#10327) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Seen when upgrading to Xcode 26.
Introduced in #8311.
Fixes flutter/flutter#173744
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3